<?php echo $this->render('layouts/__header.phtml'); ?>
<?php echo $this->render('layouts/__nav.phtml'); ?>

<link rel="stylesheet" type="text/css" href="/css/task.css" />
<script type="text/javascript" src="/js/calendar/calendar.js"></script>
<script type="text/javascript" src="/js/calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="/js/calendar/calendar-setup.js"></script>
<style type="text/css">@import url(/js/calendar/calendar.css); </style>
<script type="text/javascript" src="/js/rpt/swfobject.js"></script>
<script type="text/javascript" src="/js/base.js"></script>
<script type="text/javascript">
window.addEvent('domready', function(){

	<?php if ($this->acl->isAllowed($this->role, 'modify:date_start')) : ?>
	Calendar.setup({inputField:"date_start",ifFormat:"%Y-%m-%d",button:"calendarBeginButton",singleClick:true,step:1});
	Calendar.setup({inputField:"date_start",ifFormat:"%Y-%m-%d",button:"vBeginDate",singleClick:true,step:1});
	<?php endif; ?>
	
	<?php if ($this->acl->isAllowed($this->role, 'modify:date_end')) : ?>
	Calendar.setup({inputField:"date_end",ifFormat:"%Y-%m-%d",button:"calendarEndButton",singleClick:true,step:1});
	Calendar.setup({inputField:"date_end",ifFormat:"%Y-%m-%d",button:"vEndDate",singleClick:true,step:1});
	<?php endif; ?>

	<?php if ($this->acl->isAllowed($this->role, 'modify:actual_date_start')) : ?>
	Calendar.setup({inputField:"actual_date_start",ifFormat:"%Y-%m-%d",button:"calendarActualBeginButton",singleClick:true,step:1});
	Calendar.setup({inputField:"actual_date_start",ifFormat:"%Y-%m-%d",button:"vActualBeginDate",singleClick:true,step:1});
	<?php endif; ?>

	<?php if ($this->acl->isAllowed($this->role, 'modify:actual_date_end')) : ?>
	Calendar.setup({inputField:"actual_date_end",ifFormat:"%Y-%m-%d",button:"calendarActualEndButton",singleClick:true,step:1});
	Calendar.setup({inputField:"actual_date_end",ifFormat:"%Y-%m-%d",button:"vActualEndDate",singleClick:true,step:1});
	<?php endif; ?>

	<?php if ($this->acl->isAllowed($this->role, 'modify:launch_date')) : ?>
	Calendar.setup({inputField:"launch_date",ifFormat:"%Y-%m-%d",button:"calendarLaunchDayButton",singleClick:true,step:1});
	Calendar.setup({inputField:"launch_date",ifFormat:"%Y-%m-%d",button:"vLaunchDay",singleClick:true,step:1});
	<?php endif; ?>

	<?php if ($this->acl->isAllowed($this->role, 'modify:weight')) : ?>
		<?php if (sizeof($this->children) > 0) : ?>
		var so = new SWFObject("/js/rpt/ampie.swf", "ampie", "500", "240", "4", "#FFFFFF");
		so.addVariable("path", "/js/rpt/");
		so.addVariable("settings_file", escape("/task/piesetting"));
		so.addVariable("data_file", escape("/task/piedata"));
		so.addVariable("preloader_color", "#999999");
		so.addParam("wmode", "transparent");
		so.write("flashcontent");
		// For Task Assign
		var form_name = 'task_edit_form';
		$(form_name).getElements('input[name^=weight]').each(function(item, index){
			item.addEvent('change', function(e){
				if (countWeight(form_name)) {
					var request_uri = '<?php echo $this->pie_url;?>?ajax=1&t='+(new Date()).getTime();
					new Ajax(request_uri, {
						method: 'get',
						data: Object.toQueryString({
							data: getWeight(form_name)
						}),
						onComplete: function(){
							if ('success' == this.response.text) {
								so.write("flashcontent");
							}
						}
					}).request();
				}
			});
		});
		<?php endif; ?>
	<?php endif; ?>

	<?php if ($this->acl->isAllowed($this->role, 'modify:task_update')) : ?>
		<?php if (sizeof($this->children) == 0) : ?>
		var mySlide = new Slider($('area'), $('knob'), {
			steps: 100,
			onChange: function(step){
				$('progress').value = step;
				$('upd').setHTML(step+'%');
			}
		}).set(<?php echo $this->task['progress']; ?>);
		<?php endif; ?>
	<?php endif; ?>

	<?php if ($this->acl->isAllowed($this->role, 'modify:attachment')) : ?>
	$('attachment_file').addEvent('change', function(e){
		e = new Event(e);
		$('has_attachment').value = 'yes';
		var old_action = $('task_edit_form').action;
		// submit to iframe once
		$('task_edit_form').action = '<?php echo $this->upload_url; ?>';
		$('task_edit_form').target = 'upload_frame';
		$('task_edit_form').submit();
		// return to normal form
		$('task_edit_form').action = old_action;
		$('task_edit_form').target = '';
		e.stop();
	});
	<?php endif; ?>

	$('savebtn').addEvent('click', function(e){
		e = new Event(e);
		validate('task_edit_form');
		e.stop();
	});
	
	$('cancelbtn').addEvent('click', function(e){
		e = new Event(e);
		loadopen('<?php echo $this->cancel_url;?>');
		e.stop();
	});
});
</script>

		<form id="task_edit_form" action="<?php echo $this->this_url; ?>" method="post" enctype="multipart/form-data">
		<input type="hidden" id="has_attachment" name="has_attachment" />
		<input type="hidden" id="save" name="save" />
		
			<h2>Edit Task '<?php echo $this->task['title']; ?>'</h2>
			
			<?php if ($this->errors) : ?>
			<div class="errormsgbox">
			<?php foreach ($this->errors as $error_msg) echo '<p>'.$error_msg.'</p>'; ?>
			</div>
			<?php endif; ?>
			
			<table class="table550">
				<tr><td>&nbsp;</td></tr>

			<!-- Task Common Column Start -->
				<tr>
					<?php if ($this->acl->isAllowed($this->role, 'modify:title')) : ?>
					<td colspan="2">
						<span class="left">Title</span>
						<input name="title" type="text" class="title" value="<?php echo $this->task['title']; ?>" />
					</td>
				    <?php endif; ?>
				    <?php if ($this->acl->isAllowed($this->role, 'modify:property_id')) : ?>
				    <td>
				    	<span class="left">Property</span>
				    	<?php echo $this->formSelect('property_id', $this->task['property_id'], null, $this->entites['property']) ?>
				    </td>
				    <?php endif; ?>
				</tr>
				
				<tr>
					<?php if ($this->acl->isAllowed($this->role, 'modify:request_id')) : ?>
					<td>
						<span class="left">Requester</span>
						<?php echo $this->formSelect('request_id', $this->task['request_id'], null, $this->entites['requester']) ?>
					</td>
					<?php endif; ?>
					<?php if ($this->acl->isAllowed($this->role, 'modify:manager_id')) : ?>
				    <td>
						<span class="left">PM</span>
						<?php echo $this->formSelect('manager_id', $this->task['manager_id'], null, $this->entites['manager']) ?>
					</td>
					<?php endif; ?>
					<?php if ($this->acl->isAllowed($this->role, 'modify:developer_id')) : ?>
				    <td>
						<span class="left">Assign To</span>
						<?php echo $this->formSelect('developer_id', $this->task['developer_id'], null, $this->entites['engineer']) ?>
					</td>
					<?php endif; ?>
				</tr>
				<tr>
					<?php if ($this->acl->isAllowed($this->role, 'modify:task_type')) : ?>
					<td colspan="2">
						<span class="left">Task Type</span>
						<?php echo $this->formSelect('task_type', $this->task['task_type'], array('style' => 'width:288px'), $this->entites['type']) ?>
					</td>
					<?php endif; ?>
					<?php if ($this->acl->isAllowed($this->role, 'modify:qa_id') and $this->task['task_status']>0) : ?>
				    <td>
						<span class="left">QA</span>
						<?php echo $this->formSelect('qa_id', $this->task['qa_id'], null, $this->entites['qa']) ?>
					</td>
					<?php endif; ?>
				</tr>
				<tr>
					<?php if ($this->acl->isAllowed($this->role, 'modify:prior_reference')) : ?>
					<td colspan="2">
						<span class="left">Prior Refer</span>
						<?php echo $this->formSelect('prior_reference', $this->task['prior_reference'], array('style' => 'width:288px'), $this->entites['prior_reference']) ?>
					</td>
					<?php endif; ?>				    
					<?php if ($this->acl->isAllowed($this->role, 'modify:task_status') and $this->task['task_status']>0) : ?>
				    <td>
						<span class="left">Status</span>
						<?php echo $this->formSelect('task_status', $this->task['task_status'], null, $this->entites['status']) ?>
					</td>
					<?php endif; ?>
				</tr>
				<?php if ($this->acl->isAllowed($this->role, 'modify:man_hour')) : ?>
				<tr>
					<td colspan="3">
						<span class="left">Man Hours</span>
						<input name="man_hour" type="text" class="man_hour" value="<?php echo $this->task['man_hour']; ?>" />&nbsp;man×hour
					</td>
				</tr>
				<?php endif; ?>
				<?php if ($this->acl->isAllowed($this->role, 'modify:roadmap_id')) : ?>
				<tr>
					<td colspan="3">
						<span class="left">Roadmap</span>
						<input name="roadmap_id" type="text" maxlength="7" class="man_hour" value="<?php echo $this->task['roadmap_id']; ?>" />&nbsp;7(chars)
					</td>
				</tr>
				<?php endif; ?>
				<?php if ($this->acl->isAllowed($this->role, 'modify:cvs_tag')) : ?>
				<tr>
					<td colspan="3">
						<span class="left">CVS Tag</span>
						<input name="cvs_tag" type="text" maxlength="50" class="man_hour" value="<?php echo $this->task['cvs_tag']; ?>" />
					</td>
				</tr>
				<?php endif; ?>
				<?php if ($this->acl->isAllowed($this->role, 'modify:date_start')) : ?>
				<tr>
					<td colspan="3">
						<span class="left">Start Date</span>
						<input id="date_start" name="date_start" value="<?php if (isset($this->task['date_start'])) echo $this->task['date_start']; else echo "0000-00-00"; ?>" style="width: 80px;" type="text" readonly />
						<input type="button" id="calendarBeginButton" class="cal" style="width:20px" />
					</td>
			    </tr>
			    <?php endif; ?>
			    <?php if ($this->acl->isAllowed($this->role, 'modify:date_end')) : ?>
				<tr>
					<td colspan="3">
						<span class="left">Due Date</span>			  
						<input id="date_end" name="date_end" value="<?php if (isset($this->task['date_end'])) echo $this->task['date_end']; else echo "0000-00-00"; ?>" style="width: 80px;" type="text" readonly />
						<input type="button" id="calendarEndButton" class="cal" style="width:20px" />
					</td>
				</tr>
				<?php endif; ?>
				<?php if ($this->acl->isAllowed($this->role, 'modify:actual_date_start')) : ?>
				<tr>
					<td colspan="3">
						<span class="left">ActualStart</span>
						<input id="actual_date_start" name="actual_date_start" value="<?php if (isset($this->task['actual_date_start'])) echo $this->task['actual_date_start']; else echo "0000-00-00"; ?>" style="width: 80px;" type="text" readonly />
						<input type="button" id="calendarActualBeginButton" class="cal" style="width:20px" />
					</td>
			    </tr>
			    <?php endif; ?>
				<?php if ($this->acl->isAllowed($this->role, 'modify:actual_date_end')) : ?>
				<tr>
					<td colspan="3">
						<span class="left">Actual End</span>
						<input id="actual_date_end" name="actual_date_end" value="<?php if (isset($this->task['actual_date_end'])) echo $this->task['actual_date_end']; else echo "0000-00-00"; ?>" style="width: 80px;" type="text" readonly />
						<input type="button" id="calendarActualEndButton" class="cal" style="width:20px" />
					</td>
			    </tr>
			    <?php endif; ?>
				<?php if ($this->acl->isAllowed($this->role, 'modify:launch_date')) : ?>
				<tr>
					<td colspan="3">
						<span class="left">LaunchDay</span>
						<input id="launch_date" name="launch_date" value="<?php if (isset($this->task['launch_date'])) echo $this->task['launch_date']; else echo "0000-00-00"; ?>" style="width: 80px;" type="text" readonly />
						<input type="button" id="calendarLaunchDayButton" class="cal" style="width:20px" />
					</td>
			    </tr>
			    <?php endif; ?>
				<!--
				<tr>
					<td colspan="3"><span class="left">Authority</span></td>
				</tr>
				<tr>
					<td colspan="3"><?php echo $this->formRadio('authority', $this->task['authority'], array('style' => 'width:68px'), $this->entites['authority']) ?></td>
				</tr>
				-->
				<?php if ($this->acl->isAllowed($this->role, 'modify:description')) : ?>				
				<tr>
					<td colspan="3">
					<div style="padding:5px 0;font-weight:bold">Description</div>
					<textarea name="description"><?php echo $this->task['description']; ?></textarea></td>
			    </tr>
			    <?php endif; ?>
			<!-- Task Common Column End -->

			<!-- Task Assign Weight Start -->
			<?php if ($this->acl->isAllowed($this->role, 'modify:weight')) : ?>
				<?php if (sizeof($this->children) > 0) : ?>
				<tr>
					<td colspan="3"><span class="left_long">Sub Tasks Weight</span></td>
				</tr>
				<tr>
					<td colspan="3">
						<div id="flashcontent" style="height:200px;">
							<strong>You need to upgrade your Flash Player</strong>
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="3">
					<?php foreach ($this->children as $child) : ?>
					<div class="childtask"><?php echo $child['title']?>&nbsp;:&nbsp;<input type="text" name="weight_subtask_<?php echo $child['id']?>" class="taskweight" maxlength="3" value="<?php echo $child['weight']?>" />&nbsp;%</div>
					<?php endforeach;?>
					</td>
				</tr>
				<tr>
					<td colspan="3">
						<div id="weight_notice">
							<font style="color:black;font-weight:bold">* You can change the weight of the subtasks above !</font>
						</div>
					</td>
				</tr>
				<?php endif; ?>
			<?php endif; ?>
			<!-- Task Assign Weight End -->

			<!-- Task Updates Start -->
			<?php if ($this->acl->isAllowed($this->role, 'modify:task_update')) : ?>
				<?php if (sizeof($this->children) == 0) : ?>
				<tr>
					<td colspan="3"><span class="left">Progress</span></td>
				</tr>
				<tr>
					<td colspan="3">
					<input type="hidden" id="progress" name="progress" />
					<table>
						<tr>
						<td style="background:#ccc"><div id="area"><div id="knob" title="toggle me"></div></div></td>
						<td id="upd"></td>
						</tr>
					</table>
					</td>
				</tr>
				<?php endif; ?>
				<tr>
					<td colspan="3"><span class="common left">Task Update</span></td>
				</tr>
				<tr>
					<td colspan="3">
					<?php
					foreach($this->task['task_updates'] as $task_update) {
						echo "
							<ul class='task_update'>
								<li class='task_update_user'>
									<a href='javascript:void(0);' onclick='showTaskUpdateDetail(this,{$task_update['id']});'>
										<img src='/images/expand.gif'>
									</a>
									{$task_update['username']}
								</li>
								<li class='task_update_time' align='right'>{$task_update['update_time']}</li>
							</ul>
							<ul id='stu-{$task_update['id']}' class='task_update_content'>
								<li>{$task_update['content']}</li>
							</ul>
							  ";	
					}
					?>
					</td>
				</tr>
				<tr>
					<td colspan="3">
					<input type="hidden" name="task_update_old" value="<?php echo $this->task['task_update']; ?>"/>
					<textarea name="task_update"></textarea>
					</td>
			    </tr>
			<?php endif; ?>
			<!-- Task Updates End -->
			
			<?php if ($this->acl->isAllowed($this->role, 'modify:attachment')) : ?>
				<tr>
					<td colspan="3"><span class="common left">Attachment</span></td>
				</tr>
				<tr>
					<td colspan="3"><input id="attachment_file" name="attachment_file" type="file" /></td>
				</tr>
				<tr>
					<td colspan="3"><div id="attachment_box"><iframe id="upload_frame" name="upload_frame" src="<?php echo $this->upload_url; ?>" frameborder="0"></iframe></div></td>
				</tr>
			<?php endif; ?>
				
				<tr><td colspan="3" class="spacing"></td></tr>
				<tr>
					<td colspan="3"><input type="button" id="savebtn" value="Update" class="but" /><input id="cancelbtn" type="button" value="Cancel" class="but" /></td>
				</tr>
			</table>

		</form>

		<div id="savingbox" style="display:none;padding:2px 0px 0px 8px;width:125px;height:20px;text-align:center;position:absolute;top:0px;right:0px;background:#CC0000;color:#fff;z-index:10000;"><b>Saving ...</b></div>
		<div id="loadingbox" style="display:none;padding:2px 0px 0px 8px;width:125px;height:20px;text-align:center;position:absolute;top:0px;right:0px;background:#CC0000;color:#fff;z-index:10000;"><b>Loading ...</b></div>

<?php echo $this->render('layouts/__footer.phtml'); ?>